using System.Collections.Generic;
using SqlQueryBuilder.Clauses;
using SqlQueryBuilder.Util;

namespace SqlQueryBuilder.Criterias
{
    /// <summary>
    /// Values Criteria
    /// </summary>
    public class ValuesCriteria : AbstractValueClause, ICriteria
    {
        /// <summary>
        /// Gets or sets the value clauses.
        /// </summary>
        /// <value>The value clauses.</value>
        public List<object> valueClauses { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="ValuesCriteria"/> class.
        /// </summary>
        public ValuesCriteria()
        {
            valueClauses = new List<object>();
        }

        /// <summary>
        /// Builds the criteria.
        /// </summary>
        /// <returns></returns>
        public string BuildCriteria()
        {
            return string.Format("VALUES ({0}) ", GenerateValuesClause());
        }

        /// <summary>
        /// Generates the values clause.
        /// </summary>
        /// <returns></returns>
        private string GenerateValuesClause()
        {
            bool firstClause = true;
            string update = string.Empty;
            foreach (object valueClause in valueClauses)
            {
                if (firstClause)
                    firstClause = false;
                else
                    update = SqlMultipleFields.AddSeparator(update);

                update += FormatSQLValue(valueClause);
            }
            return update;
        }
    }
}